package com.android.duininsuoai.view.detail;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.android.duininsuoai.model.detail.MainDetail;
import com.android.duininsuoai.R;
import com.mcxtzhang.nestlistview.NestFullListView;
import com.mcxtzhang.nestlistview.NestFullListViewAdapter;
import com.mcxtzhang.nestlistview.NestFullViewHolder;


/**
 * Created by Administrator on 2016/11/16.
 */

public class PopDetailSpecChoose extends PopupWindow implements View.OnClickListener {
    private PopupWindow popupWindow;
    private Activity context;
    private int pospay = 0;
    private MainDetail mInfo;

    public PopDetailSpecChoose(Activity context, final MainDetail mInfo) {
        this.context = context;
        if (mInfo == null) {
            return;
        }
        this.mInfo = mInfo;
        View view = LayoutInflater.from(context).inflate(R.layout.pop_detail, null);
        popupWindow = new PopupWindow(view, LinearLayoutCompat.LayoutParams.MATCH_PARENT,
                LinearLayoutCompat.LayoutParams.MATCH_PARENT, true);
        popupWindow.setAnimationStyle(R.style.popWindow_anim_style);
        view.findViewById(R.id.close).setOnClickListener(this);
        view.findViewById(R.id.spec_close).setOnClickListener(this);
        view.findViewById(R.id.ok_tv).setOnClickListener(this);
        ImageView spec_thumb = (ImageView) view.findViewById(R.id.spec_thumb);
        TextView spec_price = (TextView) view.findViewById(R.id.spec_price);
        TextView spec_stock = (TextView) view.findViewById(R.id.spec_stock);
        TextView spec_spec = (TextView) view.findViewById(R.id.spec_spec);
        NestFullListView spec_list = (NestFullListView) view.findViewById(R.id.spec_list);

        spec_list.setAdapter(new NestFullListViewAdapter<MainDetail.DataBean.SpArrBean>(R.layout.item_detail_spec_check, mInfo.getData().getSp_arr()) {
            @Override
            public void onBind(int position, MainDetail.DataBean.SpArrBean testBean, NestFullViewHolder holder) {
                holder.setText(R.id.spec_title, testBean.getName());


            }
        });
//
//        spec_list.setOnItemClickListener(new NestFullListView.OnItemClickListener() {
//            @Override
//            public void onItemClick(NestFullListView nestFullListView, View view, int position) {
//                pospay = position;
//                nestFullListView.updateUI();
//                pay_id = mSortListdata.get(position).getId();
//            }
//        });
    }

    public void show(View parent) {
        ShowSpec();
        popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.update();

    }

    private void ShowSpec() {
    }

    public void close() {

        if (popupWindow != null && popupWindow.isShowing()) {

            popupWindow.dismiss();


        }


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.close:
            case R.id.spec_close:
                close();
                break;
            case R.id.ok_tv:
                close();
                break;


        }
    }


}
